package com.sky.controller.user;

import com.sky.dto.OrdersDTO;
import com.sky.dto.OrdersPaymentDTO;
import com.sky.dto.OrdersSubmitDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderPaymentVO;
import com.sky.vo.OrderSubmitVO;
import com.sky.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.annotation.Order;
import org.springframework.data.redis.connection.ReactiveSubscription;
import org.springframework.web.bind.annotation.*;

@RestController("userOrderController")
@Slf4j
@RequestMapping("/user/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @PostMapping("/submit")
    public Result<OrderSubmitVO> submit(@RequestBody OrdersSubmitDTO ordersSubmitDTO) {
        log.info("order submit: {}", ordersSubmitDTO);
        OrderSubmitVO orderSubmitVO=orderService.submit(ordersSubmitDTO);
        return Result.success(orderSubmitVO);
    }

    //todo 该方法并没有真正实现
    @PutMapping("/payment")
    public Result<OrderPaymentVO> paymentPreprocess(@RequestBody OrdersPaymentDTO ordersPaymentDTO) {
        log.info("payment preprocess: {}", ordersPaymentDTO);
        OrderPaymentVO orderPaymentVO = orderService.paymentPreprocess(ordersPaymentDTO);
        orderService.paySuccess(ordersPaymentDTO.getOrderNumber());
        return Result.success(orderPaymentVO);
    }

    //todo 接口文档没有提及
    @GetMapping("/historyOrders")
    public Result<PageResult> pageQueryOrdersForUser(Integer page, Integer pageSize, Integer status){
        log.info("pageQueryUserOrders: {}", page);
        PageResult orders=orderService.pageQueryOrdersForUser(page,pageSize,status);
        return Result.success(orders);
    }

    @GetMapping("/orderDetail/{id}")
    public Result<OrderVO> getOrderWithDetail(@PathVariable Long id){
        log.info("getOrderWithDetail: {}", id);
        OrderVO orderVO=orderService.getOrderWithDetail(id);
        return Result.success(orderVO);
    }

    @PutMapping("/cancel/{id}")
    public Result cancelOrder(@PathVariable Long id){
        log.info("cancelOrder: {}", id);
        orderService.userCancelOrderById(id);
        return Result.success();
    }

    @PostMapping("/repetition/{id}")
    public Result repetition(@PathVariable Long id){
        log.info("repetition: {}", id);
        orderService.repetition(id);
        return Result.success();
    }

    @GetMapping("/reminder/{id}")
    public Result reminderOrder(@PathVariable Long id){
        log.info("reminderOrder: {}", id);
        orderService.reminder(id);
        return Result.success();
    }







}
